;;;;
;;;; Default Yarr initialization file
;;;;

;;;; Set up I/O

(declare (*input*  System.IO.TextReader Console.In)     ;; standard input stream
         (*output* System.IO.TextWriter Console.Out)    ;; standard output stream
         (*error*  System.IO.TextWriter Console.Error)) ;; standard error stream

;;;; Error checking & debugging

(declare (*max-recursion-depth* Int32 1000))    ;; try to catch stack overflows

;;;; Load extensions

;; pretty-printer
(load (Path.Combine 
       AppDomain.CurrentDomain.BaseDirectory 
       "Yarr.Pprint.dll"))

;;;; Debugger support

(make-package "debug" :use '("system"))
(in-package "debug")

;; Enable debugger
(defun debug-on ()
  (Runtime.EnableDebugger DebuggerMode.RunToBreakpoint))

;; Enter single-step mode
(defun single-step ()
  (Runtime.EnableDebugger DebuggerMode.SingleStep))

;; Disable debugger
(defun debug-off () (Runtime.DisableDebugger))

;; Manage breakpoints (also turn on debugging if not already on)

(defun add-bkpt (obj) 
  (debug-on)
  (and (is Yarr.IDebugger Runtime.Profiler)
       (Runtime.Profiler.AddBreakpoint obj)))
  
(defun remove-bkpt (obj) 
  (debug-on)
  (and (is Yarr.IDebugger Runtime.Profiler)
       (Runtime.Profiler.RemoveBreakpoint ob)))

(defun enable-bkpt (obj)
  (debug-on)
  (and (is Yarr.IDebugger Runtime.Profiler)
       (Runtime.Profiler.EnableBreakpoint ob)))

(defun disable-bkpt (obj)
  (debug-on)
  (and (is Yarr.IDebugger Runtime.Profiler)
       (Runtime.Profiler.DisableBreakpoint obj)))

(in-package "user")
